library Wave15b initializer init requires LegacySystem

/*
Rogue company decides to take matters in their own hands. Attempts to retrieve nuke in order to eliminate Zulu threat.

player 9 - Patrolling Marines
player 11 - Technicians/Misc support forces
player 13 - Static defense
player 14 - Zulus
*/

    private function TechnicianDeath takes nothing returns nothing
        local integer i=1
        if udg_Mode==1 and udg_SectorClear==false then
            call ALICEText(10.0, "|cffff000030 XP|r penalty imposed for killing a technician." )
            loop
                exitwhen i>udg_InitialPlayers
                set udg_Experience[udg_Sorted[i]] = udg_Experience[udg_Sorted[i]]-30
                set i=i+1
            endloop
        endif
    endfunction


    private function LieutenantOliver takes nothing returns nothing
        local integer i = 1
        local unit target = udg_Hero[udg_Sorted[GetRandomInt(1,udg_Players)]]
        local real x = GetUnitX(target)+GetRandomReal(-1000.0,1000.0)
        local real y = GetUnitY(target)+GetRandomReal(-1000.0,1000.0)

        if GetWidgetLife(udg_Boss2[1])<0.405 or udg_Players<1 then
            if GetWidgetLife(udg_Boss2[1])<0.405 and udg_Mode==1 then
                set i = 1
                call ALICE2Text(10.0, "Lieutenant Oliver neutralized. |cff1e90ff15 XP|r awarded to all Marines." )
                loop
                    exitwhen i>udg_InitialPlayers
                    if GetPlayerSlotState(ConvertedPlayer(udg_Sorted[i]))!=PLAYER_SLOT_STATE_LEFT then
                        set udg_Experience[udg_Sorted[i]] = udg_Experience[udg_Sorted[i]] + 15
                    endif
                    set i=i+1
                endloop
            endif
            call DisableTrigger(GetTriggeringTrigger())
        elseif GetRandomInt(0,2)!=1 then
            call PolledWait(10.)
            call PingMinimapEx(x,y,2.0,204,196,115,false)
            call PolledWait(2.)
            call ArtHandler(udg_Boss2[1],x,y,5,1.0,250,2.0,0)
            call TriggerSleepAction(0.)
            call EarShockArea(x,y,800)
            call PolledWait(5.5)
        endif

        set target = null
    endfunction

    private function GolfCompanyEntry takes nothing returns nothing
        local integer i = 1
        local integer i2 = 1
        local integer i3 = 1
        local integer side
        local integer id
        local integer spawn = GetRandomInt(1,4)
        local real x
        local real y
        local real array dx
        local real array dy
        local unit u
        local trigger t = CreateTrigger()
        loop
            exitwhen i>udg_Spawn+2
            set side=GetRandomInt(1,4)
            set x = GetRandomReal(GetRectMinX(udg_UndeadRandomSpawn[side]),GetRectMaxX(udg_UndeadRandomSpawn[side]))
            set y = GetRandomReal(GetRectMinY(udg_UndeadRandomSpawn[side]),GetRectMaxY(udg_UndeadRandomSpawn[side]))
            call TriggerSleepAction(0.)
            set u = CreateUnit(Player(13),'hrtt',x,y,0.0)
            call RemoveGuardPosition(u)
            call IssuePointOrder(u,"attack",GetRandomReal(-2000.0,600.0),GetRandomReal(-1600.0,1500.0))
            call TriggerSleepAction(0.)
            set u = CreateUnit(Player(13),'z008',x,y,0.0)
            call RemoveGuardPosition(u)
            call UnitAddItemById(u,'I001') //Composite
            call IssuePointOrder(u,"attack",GetRandomReal(-2000.0,600.0),GetRandomReal(-1600.0,1500.0))
            call TriggerSleepAction(0.)
            if GetRandomInt(0,1)==1 then
                set u = CreateUnit(Player(13),'z008',x,y,0.0) //Rifleman
            elseif GetRandomInt(0,1)==1 then
                set u = CreateUnit(Player(13),'z009',x,y,0.0) //Flamethrower
            else
                set u = CreateUnit(Player(13),'z004',x,y,0.0) //Engineer
            endif
            call RemoveGuardPosition(u)
            call UnitAddItemById(u,'I001') //Composite
            call IssuePointOrder(u,"attack",GetRandomReal(-2000.0,600.0),GetRandomReal(-1600.0,1500.0))
            if GetRandomInt(0,3)==1 and udg_InitialPlayers>3 then
                set id='z00F' //Marksmen
            else
                set id='z000'
            endif
            set u = CreateUnit(Player(13),id,x,y,0.0)
            call RemoveGuardPosition(u)
            call IssuePointOrder(u,"attack",GetRandomReal(-2000.0,600.0),GetRandomReal(-1600.0,1500.0))
            if i==1 then
                set udg_Boss2[1] = CreateUnit(Player(13),'z00H',x,y,0.0)
                call RemoveGuardPosition(udg_Boss2[1])
                call IssuePointOrder(udg_Boss2[1],"attack",GetRandomReal(-2000.0,600.0),GetRandomReal(-1600.0,1500.0))
            endif
            set i=i+1
        endloop
        set u = null
        set i=1
        loop //Minefield
            exitwhen i>50
            loop
                set x = GetRandomReal(GetRectMinX(udg_PlayerSpawnBoundary),GetRectMaxX(udg_PlayerSpawnBoundary))
                set y = GetRandomReal(GetRectMinY(udg_PlayerSpawnBoundary),GetRectMaxY(udg_PlayerSpawnBoundary))
                set dx[1] = x-GetUnitX(udg_Hero[udg_Sorted[1]])
                set dy[1] = y-GetUnitY(udg_Hero[udg_Sorted[1]])
                set dx[2] = x-GetUnitX(udg_Hero[udg_Sorted[2]])
                set dy[2] = y-GetUnitY(udg_Hero[udg_Sorted[2]])
                set dx[3] = x-GetUnitX(udg_Hero[udg_Sorted[3]])
                set dy[3] = y-GetUnitY(udg_Hero[udg_Sorted[3]])
                set dx[4] = x-GetUnitX(udg_Hero[udg_Sorted[4]])
                set dy[4] = y-GetUnitY(udg_Hero[udg_Sorted[4]])
                exitwhen dx[1]*dx[1]+dy[1]*dy[1]>12250000.0 and dx[2]*dx[2]+dy[2]*dy[2]>12250000.0 and dx[3]*dx[3]+dy[3]*dy[3]>12250000.0 and dx[4]*dx[4]+dy[4]*dy[4]>12250000.0 //3500 radius
                set x = GetRandomReal(GetRectMinX(udg_PlayerSpawnBoundary),GetRectMaxX(udg_PlayerSpawnBoundary))
                set y = GetRandomReal(GetRectMinY(udg_PlayerSpawnBoundary),GetRectMaxY(udg_PlayerSpawnBoundary))
            endloop
            call CreateUnit(Player(13),'n013',x,y,0.0)
            call TriggerSleepAction(0.)
            set i=i+1
        endloop
        call TriggerAddAction(t,function TechnicianDeath)
        set i=1
        loop
            exitwhen i>10
            set x = GetRandomReal(GetRectMinX(gg_rct_Town),GetRectMaxX(gg_rct_Town))
            set y = GetRandomReal(GetRectMinY(gg_rct_Town),GetRectMaxY(gg_rct_Town))
            set u = CreateUnit(Player(11),'n014',x,y,0.0)
            call RemoveGuardPosition(u)
            call TriggerRegisterUnitEvent(t,u,EVENT_UNIT_DEATH)
            call TriggerSleepAction(0.)
            set i=i+1
        endloop
        set t=CreateTrigger()
        if udg_InitialPlayers<4 then
            call TriggerRegisterTimerEvent(t,40.0,true)
        else
            call TriggerRegisterTimerEvent(t,25.0,true)
        endif
        call TriggerAddAction(t,function LieutenantOliver)
        set t=null
    endfunction

    private function AIGolfCompany takes nothing returns nothing
        local group g = CreateGroup()
        local group g2 = CreateGroup()
        local unit u
        local real x
        local real y
        local integer i=1
        local integer id

    // Golf Company Stationary Forces

        call GroupEnumUnitsOfPlayer(g,Player(13),null)
        loop
            set u = FirstOfGroup(g)
            exitwhen u==null
            set x=GetRandomReal(-2000.0,600.0)
            set y=GetRandomReal(-1600.0,1500.0)
            if GetRandomInt(0,4)==1 then
                call PolledWait(GetRandomReal(0.0,1.0))
            endif
            call IssuePointOrder(u,"attack",x,y)
            call GroupRemoveUnit(g,u)
        endloop
        call DestroyGroup(g)

    // Golf Company Assault Forces

        set g=CreateGroup()
        call GroupEnumUnitsOfPlayer(g,Player(9),null)
        loop
            exitwhen i>udg_Players
            if IsUnitVisible(udg_Hero[udg_Sorted[i]],Player(9)) then
                call GroupAddUnit(g2,udg_Hero[udg_Sorted[i]])
            endif
            set i=i+1
        endloop
        set u = GroupPickRandomUnit(g2)
        if u==null then
            set u = udg_Hero[udg_Sorted[GetRandomInt(1,udg_Players)]]
        endif
        if GetWidgetLife(u)<=0.405 then
            set x = GetRandomReal(-7000.0,11000.0)
            set y = GetRandomReal(-4000.0,14000.0)
        else
            set x = GetUnitX(u)
            set y = GetUnitY(u)
        endif
        loop
            set u = FirstOfGroup(g)
            exitwhen u==null
            set id=GetUnitTypeId(u)
            if id=='n00R' then //RAVEN Mine
                call IssuePointOrder(u,"move",x,y)
            else
                call IssuePointOrder(u,"attack",x,y)
            endif
            if GetRandomInt(0,6)==1 then
                call PolledWait(GetRandomReal(0.0,1.0))
            endif
            call GroupRemoveUnit(g,u)
        endloop

        call DestroyGroup(g2)
        set g2 = null
        call DestroyGroup(g)
        set g = null
        if GetRandomInt(1,85)==1 then
            call StartSound(udg_Ambience[GetRandomInt(1,8)])
        endif
    endfunction


    private function Wave15b takes nothing returns nothing
        local integer i=1
        local real trans = 0.0
        local trigger t
        if udg_Players<1 or udg_Chapter==3 then
            return
        endif
        if GetRandomInt(0,10)==1 then
            set trans = 40.0
        endif
        set udg_Chapter = 3
        set udg_Intermission = true
        set udg_XPFactor = udg_XPFactor*5
        set udg_Lighting = true
        call SquadRatingCalc.execute()
        call SetPlayerName(Player(9),"Golf Company")
        call SetPlayerName(Player(13),"Golf Company")
        set udg_MarineSpawnArea[1] = gg_rct_CaravanEnd
        set udg_MarineSpawnArea[2] = gg_rct_South_Road
        set udg_MarineSpawnArea[3] = gg_rct_CaravanCEnd
        set udg_MarineSpawnArea[4] = gg_rct_West_Road
        set udg_MarineStagingArea[1] = gg_rct_TownEntranceNorth
        set udg_MarineStagingArea[2] = gg_rct_TownEntranceSouth
        set udg_MarineStagingArea[3] = gg_rct_TownEntranceEast
        set udg_MarineStagingArea[4] = gg_rct_TownEntranceWest
        set udg_LZNames[0] = "Alpha"
        set udg_LZNames[1] = "Bravo"
        set udg_LZNames[2] = "Charlie"
        set udg_LZNames[3] = "Delta"
        set udg_LZNames[4] = "Epsilon"
        set udg_LZNames[5] = "Gamma"
        set udg_ReloadText = 100
        set udg_Immortal = 'n001'
        set udg_Ghoul = 'u003'
        set udg_Parasite = 'n00J'
        set udg_LostCause = true
        call PauseAllUnitsBJ(true)
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, 1.0, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, trans )
        call ShowInterface(false,1.0)
        call ClearTextMessages()
        call PolledWait(1.5)
        call StartSound(gg_snd_Message)
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, "                                                                             |cff8b864eLost Cause|r" )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call PauseAllUnitsBJ(true)
        call PolledWait(5.5)
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEIN, 1.0, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, trans )
        call ShowInterface(true,1.0)
        call ClearTextMessages()
        set udg_Lighting = false
        call PolledWait(1.)
        set udg_Intermission = false
        call PauseAllUnitsBJ(false)
        call IntermissionRestore.execute()
        call PolledWait(5.)
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, 0.001, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0 )
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEIN, 0.001, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0 )
        call TriggerSleepAction(0.)
        call IntermissionRestore()
        call SetImmortalSpawnEnabled(true)
        call SetCrepitusSpawnEnabled(true)
        call SetGhoulSpawnEnabled(true)
        call SetDynamicEvasionEnabled(true)
        if udg_Mode==4 and udg_Players>0 then
            call ALICEText(10.0, "Chapter 2 Complete. |cff1e90ff100 XP|r awarded to " + GetPlayerName(ConvertedPlayer(udg_Sorted[1])) )
            set udg_Experience[udg_Sorted[1]] = udg_Experience[udg_Sorted[1]] + 100
        endif
		
		call DisableRareItemDropsOnDeath(Player(9))
		call DisableRareItemDropsOnDeath(Player(11))
		call DisableRareItemDropsOnDeath(Player(13))
		call DisableRareItemDropsOnDeath(Player(14))


        loop
            exitwhen i>udg_InitialPlayers
            call DisableRareItemDropsOnDeath(ConvertedPlayer(udg_Sorted[i]))
            set i=i+1
        endloop

		set t = CreateTrigger()
        call TriggerAddAction(t,function AIGolfCompany)
        call TriggerRegisterTimerEvent(t,10.0,true)
        //call DisableTrigger(gg_trg_ShowStats)

        call SetAINeutralVictimEnabled(false)
        call DisableAilmentChecks()
        //call DisableTrigger(gg_trg_Article_15)
        call SetGhoulSpawnEnabled(false)
        call SetSkyModel( "Environment\\Sky\\FelwoodSky\\FelwoodSky.mdl" )
        call TriggerSleepAction(0.)
        set i=1
        loop
            exitwhen i>udg_Players
            if GetUnitTypeId(udg_Hero[udg_Sorted[i]])=='H000' or GetUnitTypeId(udg_Hero[udg_Sorted[i]])=='H007' then //FT or CE
                call UnitAddAbility(udg_Hero[udg_Sorted[i]],'A05W') //Delta Camoflage
            endif
            set i=i+1
        endloop
        
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9],bj_FORCE_PLAYER[11],bj_ALLIANCE_NEUTRAL)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[11],bj_FORCE_PLAYER[9],bj_ALLIANCE_NEUTRAL)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[14],bj_FORCE_PLAYER[11],bj_ALLIANCE_NEUTRAL) //Hopefully this is right
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13],bj_FORCE_PLAYER[11],bj_ALLIANCE_NEUTRAL)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[11],bj_FORCE_PLAYER[13],bj_ALLIANCE_NEUTRAL)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9],bj_FORCE_PLAYER[14],bj_ALLIANCE_NEUTRAL)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[14],bj_FORCE_PLAYER[9],bj_ALLIANCE_NEUTRAL)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13],bj_FORCE_PLAYER[14],bj_ALLIANCE_NEUTRAL)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[14],bj_FORCE_PLAYER[13],bj_ALLIANCE_NEUTRAL)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9],bj_FORCE_PLAYER[13],bj_ALLIANCE_NEUTRAL)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13],bj_FORCE_PLAYER[9],bj_ALLIANCE_NEUTRAL)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9],udg_FireTeamA,bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(udg_FireTeamA,bj_FORCE_PLAYER[9],bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9],udg_FireTeamB,bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(udg_FireTeamB,bj_FORCE_PLAYER[9],bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13],udg_FireTeamA,bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(udg_FireTeamA,bj_FORCE_PLAYER[13],bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13],udg_FireTeamB,bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(udg_FireTeamB,bj_FORCE_PLAYER[13],bj_ALLIANCE_UNALLIED)
        call TriggerSleepAction(0.)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13], udg_EchoCompany, bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(udg_EchoCompany, bj_FORCE_PLAYER[13], bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9], udg_EchoCompany, bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(udg_EchoCompany, bj_FORCE_PLAYER[9], bj_ALLIANCE_UNALLIED )
        call TriggerSleepAction(0.)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13], udg_EchoCasualties, bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(udg_EchoCasualties, bj_FORCE_PLAYER[13], bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9], udg_EchoCasualties, bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(udg_EchoCasualties, bj_FORCE_PLAYER[9], bj_ALLIANCE_UNALLIED )

        set udg_ZStart = 900
        set udg_ZEnd = 2775
        call FogTransition(0.1)
        set udg_CurrentWave = 15
        call GenericActions.execute()
        call PlatoonReinforcements.execute()
        call C130Wave15.execute()
        call MultiboardSetTitleText( udg_SquadStatus, "Standby for Orders.." )
        call MBSet( udg_SquadStatus, 1, 1, "Standby for Orders.." )
        set i = 1
        loop
            exitwhen i>udg_InitialPlayers
            call SetPlayerTechResearched(ConvertedPlayer(udg_Sorted[i]),'R00H',1)
            set i=i+1
        endloop
        call PolledWait(25.)
        call GeneralText(5.0, "|cffcd950cCapt. Barnes|r : Third Platoon, Golf Company is here to relieve you of duty." )
        call PolledWait(5.)
        call GeneralText(5.0, "|cffcd950cMarine|r : We only take orders from Battalion and they haven't said a word about this, sir." )
        call PolledWait(10.)
        call GeneralText(5.0, "|cffcd950cCapt. Barnes|r : Top brass doesn't know what they're doing. We have to nuke this place before it's too late." )
        call PolledWait(5.)
        call GeneralText(5.0, "|cffcd950cMarine|r : Did I hear that right?" )
        call PolledWait(5.)
        call GeneralText(5.0, "|cffcd950cCapt. Barnes|r : A price we must pay. There is no alternative." )
        call PolledWait(5.)
        call GeneralText(5.0, "|cffcd950cCapt. Barnes|r : Don't interfere with what we're doing. We won't hesitate to use force." )
        call PolledWait(10.)
        call GeneralText(5.0, "|cffcd950cIron Hand|r : He's completely lost it! You're not going to let that mad man go through with his plans. Make your way to Ravenholm." )
        call MBSet( udg_SquadStatus, 1, 1, "Objective : Secure the perimeter around Ravenholm" )
        call QuestSetDescription(udg_CurrentOrders, "Secure the perimeter around Ravenholm" )
        call ALICEText(5.0, "|cff8b864eNew Objective|r : Secure the perimeter around Ravenholm." )
        call SpawnRectRandom(gg_rct_SpawnNorthWaterfall,Player(9),'z008',GetRandomInt(1,udg_Spawn))
        call SpawnRectRandom(gg_rct_SpawnTownEastCave,Player(9),'z008',GetRandomInt(1,udg_Spawn))
        call PolledWait(7.)
        call GeneralText(7.0, "|cffcd950cMarine|r : Us against an entire company is suicide. I hope you know what you're doing, Iron Hand." )
        call PolledWait(5.)
        call GeneralText(5.0, "|cffcd950cIron Hand|r : Our closest forces are thrity minutes away. You're our only hope, god'dammit." )
        call PolledWait(8.)
        call GolfCompanyEntry.execute()
        call PolledWait(20.)
        call GankMarine(Player(9),'z008',2+GetRandomInt(1,udg_Spawn),2600,4000)
        call PolledWait(10.)
        call GankMarine(Player(9),'z004',2+GetRandomInt(1,udg_Spawn),2600,4000)
        call RandomSpawn2('hgyr',1,1) //Cobra
        call PolledWait(10.)
        if GetRandomInt(0,2)==1 and udg_InitialPlayers>3 then
            call RandomSpawn2('h001',1,1) //Apache
        endif
        call MultiboardSetTitleText( udg_SquadStatus, "Secure the perimeter around Ravenholm." )
        call MBSet( udg_SquadStatus, 1, 1, "Secure the perimeter around Ravenholm" )
        call GeneralText(5.0, "|cffcd950cIron Hand|r : There are technicians with them in Ravenholm. They were brought against their will and we want them alive." )
        call QuestSetDescription(udg_CurrentOrders, "Secure the perimeter around Ravenholm. Keep the technicians alive. Lieutenant Oliver is the company's Forward Observer; take him out and they won't be able to call any Fire Missions." )
        call PolledWait(60.*udg_Pace)
        if udg_Players>0 then
            call ExecuteRegisteredFunction("Wave16b")
            //call Wave16b.execute()
        endif
    endfunction


    private function init takes nothing returns nothing
        call RegisterFunction("Wave15b", function Wave15b)
    endfunction
    
endlibrary
